from autoframe.common.base import Base, By
from selenium import webdriver
import time


class Browse(Base):
    def browse1(self):
        # 循环出导航栏9个栏位
        for i in range(len(self.driver.find_elements(By.CLASS_NAME, 'cat1'))):
            # 依次点击导航栏9个栏位
            self.driver.find_elements(By.CLASS_NAME, 'cat1')[i].click()
            # 判断导航栏里是否有商品
            if self.driver.find_element(By.CLASS_NAME, 'tdl').text > '0':
                # 如果有商品依次点击商品
                for l in range(len(self.driver.find_elements(By.CLASS_NAME, 'goodsItem'))):
                    self.driver.find_elements(By.CLASS_NAME, 'goodsItem')[l].click()
                    self.driver.back()
                    # 判断是否有下一页
                if self.driver.find_elements(By.CLASS_NAME, 'next'):
                    # 如果有下一页，点击下一页
                    self.driver.find_element(By.CLASS_NAME, 'next').click()
                    # 循环点击下一页商品
                    for h in range(len(self.driver.find_elements(By.CLASS_NAME, 'goodsItem'))):
                        self.driver.find_elements(By.CLASS_NAME, 'goodsItem')[h].click()
                        self.driver.back()
                    self.driver.back()
                self.driver.back()
            else:
                self.driver.back()

    def browse2(self, navigation):
        # 获取导航栏的文本内容
        return self.driver.find_elements(By.CLASS_NAME, 'cat1')[navigation].text

    def browse3(self, navigation):
        # 获取点击进入导航栏的面包屑文本内容
        self.driver.find_elements(By.CLASS_NAME, 'cat1')[navigation].click()
        return self.driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/div/div/a[2]').text


if __name__ == '__main__':
    pass
